<template>
  <svg :class="svgClass" v-bind="$attrs" :style="{ color: color, 'font-size': size }" aria-hidden="true">
    <use :xlink:href="iconName" />
  </svg>
</template>

<script setup lang="ts">
const props = defineProps<{
  name: string
  color?: string
  size?: string
}>()

const iconName = computed(() => `#icon-${props.name}`)

const svgClass = computed(() => {
  if (props.name) {
    return `svg-icon icon-${props.name}`
  }
  return 'svg-icon'
})
</script>

<style lang="scss" scoped>
.svg-icon {
  width: 1em;
  height: 1em;
  fill: currentColor;
  vertical-align: middle;
  font-size: 1.2em;
}
</style>
